-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subsys: add MODBUS subsystem #26516
subsys: add MODBUS subsystem #26516
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A brief review of the "main" commit.
subsys/modbus/mb_rtu_internal.h
Outdated
atomic_t state; | ||
|
||
#ifdef CONFIG_MODBUS_RTU_FC08_DIAGNOSTIC | ||
uint16_t mbs_msg_ctr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need the mbs_
prefix in those? they are already namespaced inside the struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason is that this counters are used only by the server (MODBUS_RTU_FC08_DIAGNOSTIC depends on server mode).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0af6249
to
07e8d80
Compare
9f81f07
to
c93f5e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this live under subsys/mgmt/modbus
?
Add function to get Modbus RTU interface index according to interface name. This can be used to clearly identify interfaces in the application. Signed-off-by: Johann Fischer <[email protected]>
Fix ASCII frame reception and add test for ASCII mode. Signed-off-by: Johann Fischer <[email protected]>
Reset buffer after reception, even if an error occurs. Signed-off-by: Johann Fischer <[email protected]>
Rename MODBUS RTU API to common MODBUS API. Signed-off-by: Johann Fischer <[email protected]>
Remove RTU from configuration and headers Signed-off-by: Johann Fischer <[email protected]>
Rename mb_rtu_ to modbus_. Signed-off-by: Johann Fischer <[email protected]>
Remove _rtu_ from modbus test. Signed-off-by: Johann Fischer <[email protected]>
Use enum for MODBUS mode. Signed-off-by: Johann Fischer <[email protected]>
Move MODBUS over serial line code to own source file. Signed-off-by: Johann Fischer <[email protected]>
Move serial line config outside context. Signed-off-by: Johann Fischer <[email protected]>
Make MODBUS support over serial line optional. Signed-off-by: Johann Fischer <[email protected]>
Prefix internal functions and structs with modbus_. Use unit_id consistently instead of node_addr. Fix mbm_ remainder and rename to mbc_. Rename struct modbus_frame to modbus_adu since ADU is closer to what the structure represents. Let the compiler/linker do the job and remove ifdef around mbc_validate_fc03fp_response(). Signed-off-by: Johann Fischer <[email protected]>
Let the core call the modbus_tx_adu() to make the process more comprehensible. Move tx-wait-for-rx handling outside of client code. Signed-off-by: Johann Fischer <[email protected]>
Return ETIMEDOUT on timeout instead of EIO. Signed-off-by: Johann Fischer <[email protected]>
Document return values of internal functions. Signed-off-by: Johann Fischer <[email protected]>
Use commot parameter structure to configure server or client interfaces. Signed-off-by: Johann Fischer <[email protected]>
MODBUS raw ADU support allows to implement MODBUS messaging service over TCP or UDP. Signed-off-by: Johann Fischer <[email protected]>
Add raw ADU support test. Signed-off-by: Johann Fischer <[email protected]>
Add MODBUS TCP server sample. Signed-off-by: Johann Fischer <[email protected]>
Add TCP to serial line gateway. Signed-off-by: Johann Fischer <[email protected]>
Update description and add TCP sample references. Signed-off-by: Johann Fischer <[email protected]>
Follow modern way to configure LEDs GPIO using struct gpio_dt_spec and GPIO_DT_SPEC_GET. Signed-off-by: Johann Fischer <[email protected]>
Follow modern way to configure DE,RE GPIO using struct gpio_dt_spec. Signed-off-by: Johann Fischer <[email protected]>
91400b3
to
cda8c30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scancode toolkit failures are false positives. The files include an SPDX identifier for Apache v2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit late with my comments, but I'm adding them anyway, just in case there will be a follow up PR.
|
||
static int init_modbus_server(void) | ||
{ | ||
const uint32_t mb_rtu_br = 19200; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to be used.
static int init_modbus_server(void) | ||
{ | ||
const uint32_t mb_rtu_br = 19200; | ||
const char iface_name[] = {DT_PROP(DT_INST(0, zephyr_modbus_serial), label)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way you create a local array (on stack) and fill it with the provided string (those brackets are actually confusing). You need to use then log_strdup(iface_name)
below, otherwise its content will be lost.
But I guess this was not intended and the following would work here:
const char *iface_name = DT_PROP(DT_INST(0, zephyr_modbus_serial), label);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anangl agree, Agree. Nicer to see the latter.
The const
will make sure that this data is stored in RO region (flash). How is stack related here?
|
||
static int init_modbus_client(void) | ||
{ | ||
const char iface_name[] = {DT_PROP(DT_INST(0, zephyr_modbus_serial), label)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the corresponding comment in samples/subsys/modbus/rtu_server/src/main.c
.
const char iface_name[] = {DT_PROP(DT_INST(0, zephyr_modbus_serial), label)}; | |
const char *iface_name = DT_PROP(DT_INST(0, zephyr_modbus_serial), label); |
err = modbus_write_coil(client_iface, node, addr++, true); | ||
if (err != 0) { | ||
LOG_ERR("FC05 failed with %d", err); | ||
return; | ||
} | ||
|
||
k_msleep(sleep); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be placed in a loop, to avoid code duplication.
If connected directly the MCU pin should be configured | ||
as active high. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be confusing, as in both provided overlays this signal is actually active low. Perhaps this sentence could be dropped. Similarly in the RE case. For the same reason, "nRE" and "DE" markings in descriptions could be dropped as well. I don't think they actually bring much value.
|
||
static int init_backend_iface(void) | ||
{ | ||
const char bend_name[] = {DT_PROP(DT_INST(0, zephyr_modbus_serial), label)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the corresponding comment in samples/subsys/modbus/rtu_server/src/main.c
.
const char bend_name[] = {DT_PROP(DT_INST(0, zephyr_modbus_serial), label)}; | |
const char *bend_name = DT_PROP(DT_INST(0, zephyr_modbus_serial), label); |
After this change, you won't need this log_strdup
below.
Add MODBUS
RTU (over serial line)subsystem.MODBUS
RTUimplementation supports booth server andclient roles. Some components of the implementation are based
on the uC/Modbus stack, which was published under Apache license.